/**
 *******************************************************************************************************************************************
 * @file        bsp_init.c
 * @brief       板级硬件外设初始化
 * @details     /
 * @since       Change Logs:
 * Date         Author       Notes
 * 2022-12-08   lzh          the first version
 * @remark      /
 *******************************************************************************************************************************************
 * @attention
 *
 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
 * REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
 * FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
 * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
 * -ECTION WITH THEIR PRODUCTS.
 *
 * @copyright   2012 Synwit Technology
 *******************************************************************************************************************************************
 */
#include "bsp_init.h"
#include "user_app.h"
static void nvic_init(void);

/**
 * @brief   初始化所有的硬件设备, 该函数配置CPU寄存器和外设的寄存器并初始化一些全局变量(只需要调用一次)
 */
void bsp_init(void)
{
    /* 已在 startup_SWM341.s 的 Reset_Handler 中调用
    SystemInit();
    sfc_init();   //初始化总线上外挂的SPI-Flash, 将其映射至MCU内部(可选外设)
    sdram_init(); //初始化总线上外挂的SDRAM<芯片内置>, 将其映射至MCU内部(可选外设)
    */
    __disable_irq();
    nvic_init();
    systick_init();
    uart_debug_init();
	  BLUE_uart_init();
	  led_debug_init();
    //jpeg_init();
    crc_init();
   // USBH_HW_Init();
    //dac_init();
	  buzzer_init();
    __enable_irq();
}

/**
 * @brief   对用户使用的可编程硬件中断设置优先级及分组
 */
static void nvic_init(void)
{
    /* 分组默认为 0 (注意这里和 ST 的 NVIC_PriorityGroup_0 宏不是一个意思,请勿混淆), 设为 0 表示全部为抢占优先级, 无子优先级
     * SWM341 使用 __NVIC_PRIO_BITS == 3 bit, 支持 4 种优先级分组(0 ~ 3), 8级优先级(0 ~ 7)
     * 如无必要, 请勿调整优先级分组, 默认分组即可应用 RTOS.
     */
    /* NVIC_SetPriorityGrouping(0); //优先级分组设定, 只需要被调用一次，一旦分组确定就最好不要更改，否则容易造成程序分组混乱 */
    /* NVIC_SetPriority(IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), PreemptPriority, SubPriority)); //抢断/子 优先级设定(总) */
    /* 使能 LCD 中断后再考虑打开此注释
    NVIC_SetPriority(LCD_IRQn,    NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 0, 0));

    NVIC_SetPriority(BTIMR0_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));
    NVIC_SetPriority(BTIMR1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));

    NVIC_SetPriority(GPIOM_IRQn,  NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));
    NVIC_SetPriority(GPIOD_IRQn,  NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));

    NVIC_SetPriority(UART0_IRQn,  NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));

    NVIC_SetPriority(JPEG_IRQn,   NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));
    NVIC_SetPriority(DMA_IRQn,    NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));
    NVIC_SetPriority(USB_IRQn,    NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 0));
    */
}
